/**
 * 主题切换控制器 - Theme Switcher Controller
 * @event DOMContentLoaded - 当初始HTML文档加载完成时触发 | Fires when initial HTML document has been completely loaded
 * @listens document#DOMContentLoaded
 */
document.addEventListener('DOMContentLoaded', () => {
    // 获取主题切换按钮 | Get theme toggle button
    const themeToggle = document.querySelector('.moon-icon');
    
    /**
     * 处理主题切换点击事件 | Handle theme toggle click event
     * @event click
     * @listens HTMLElement#click
     */
    themeToggle.addEventListener('click', () => {
        // 切换body类名和图标样式 | Toggle body class and icon styles
        document.body.classList.toggle('light-theme');
        themeToggle.classList.toggle('fa-moon');
        themeToggle.classList.toggle('fa-sun');
        
        // 持久化主题状态到本地存储 | Persist theme state to localStorage
        const isLight = document.body.classList.contains('light-theme');
        localStorage.setItem('theme', isLight ? 'light' : 'dark');
    });

    // 初始化主题状态 | Initialize theme state
    const savedTheme = localStorage.getItem('theme') || 'dark';
    document.body.classList.add(savedTheme === 'light' ? 'light-theme' : '');
    
    // 设置初始图标类名 | Set initial icon classes
    themeToggle.className = savedTheme === 'light' 
        ? 'moon-icon fas fa-sun' 
        : 'moon-icon fas fa-moon';

    // 添加红色X标记
    document.querySelectorAll('.nav-link, .dropdown-content a').forEach(link => {
        if (link.getAttribute('href') === '#' || link.getAttribute('href') === '') {
            link.classList.add('red-x');
        }
    });
});

/**
 * 搜索框交互控制器 - Search Box Interaction Controller
 */
const searchInput = document.querySelector('.search-bar input');

/**
 * 处理搜索框聚焦事件 | Handle search input focus event
 * @event focus
 * @listens HTMLInputElement#focus
 */
searchInput.addEventListener('focus', function () {
    this.placeholder = '请输入关键词进行搜索';
});

/**
 * 处理搜索框失焦事件 | Handle search input blur event
 * @event blur
 * @listens HTMLInputElement#blur
 */
searchInput.addEventListener('blur', function () {
    this.placeholder = '搜索';
});